﻿/*!
 *      Input.cs         
 *      Date: 26/01/2012
 *      
 *      ----------------------------------------------------------------------
 *      A static wrapper for tracking: mouse, keyboard, and gamepad 1-4 input.
 *      ----------------------------------------------------------------------
 * 
 *      Usage:
 *      On Initialize:
 *          Call: Input.INIT();
 *      On Update:
 *          Call: Input.UPDATE();
 *      To Check Devices:
 *          Ex.
 *              To check if a key is pressed:
 *                  if (Input.Keeb_Now.IsKeyDown(Keys.Space)) Take_Action();
 *              To check if player 2's 'A' button is down:
 *                  if (Input.Gam3_Now.Buttons.A == ButtonState.Pressed) Take_Action();
 *              To check where the mouse is on screen:
 *                  if (Input.Mous_Now.X > 200f) Take_Action();
 * 
 *      Author:
 *      Adrian Seeley adrian@gatosomina.com
 *      
 *      License:
 *      FULLY OPEN
 */


using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace XNAREUSABLES
{
    /// <summary>
    /// A static handler for all game input
    /// </summary>
    public static class Input
    {
        // Members
        private static KeyboardState keeb_now;          // The current keyboard state
        private static KeyboardState keeb_then;         // The keyboard state last frame
        private static MouseState    mous_now;          // The current mouse state
        private static MouseState    mous_then;         // The mouse state last frame
        private static GamePadState  gam1_now;          // The current player 1 gamepad state 
        private static GamePadState  gam1_then;         // The player 1 gamepad state last frame
        private static GamePadState  gam2_now;          // The current player 2 gamepad state 
        private static GamePadState  gam2_then;         // The player 2 gamepad state last frame
        private static GamePadState  gam3_now;          // The current player 3 gamepad state 
        private static GamePadState  gam3_then;         // The player 3 gamepad state last frame
        private static GamePadState  gam4_now;          // The current player 4 gamepad state 
        private static GamePadState  gam4_then;         // The player 4 gamepad state last frame

        //Accessors
        public static KeyboardState Keeb_Now  { get { return keeb_now ; } }
        public static KeyboardState Keeb_Then { get { return keeb_then; } }
        public static MouseState    Mous_Now  { get { return mous_now ; } }
        public static MouseState    Mous_Then { get { return mous_then; } }
        public static GamePadState  Gam1_Now  { get { return gam1_now ; } }
        public static GamePadState  Gam1_Then { get { return gam1_then; } }
        public static GamePadState  Gam2_Now  { get { return gam2_now ; } }
        public static GamePadState  Gam2_Then { get { return gam2_then; } }
        public static GamePadState  Gam3_Now  { get { return gam3_now ; } }
        public static GamePadState  Gam3_Then { get { return gam3_then; } }
        public static GamePadState  Gam4_Now  { get { return gam4_now ; } }
        public static GamePadState  Gam4_Then { get { return gam4_then; } }

        /// <summary>
        /// Called once at the start of application to initialize all members.
        /// </summary>
        public static void INIT()
        {
            keeb_now  = Keyboard.GetState();
            keeb_then = Keyboard.GetState();
            mous_now  = Mouse.GetState();
            mous_then = Mouse.GetState();
            gam1_now  = GamePad.GetState(PlayerIndex.One);
            gam1_then = GamePad.GetState(PlayerIndex.One);
            gam2_now  = GamePad.GetState(PlayerIndex.Two);
            gam2_then = GamePad.GetState(PlayerIndex.Two);
            gam3_now  = GamePad.GetState(PlayerIndex.Three);
            gam3_then = GamePad.GetState(PlayerIndex.Three);
            gam4_now  = GamePad.GetState(PlayerIndex.Four);
            gam4_then = GamePad.GetState(PlayerIndex.Four);
        }   //END FUNCTION INIT

        /// <summary>
        /// Called each frame to update all input values.
        /// </summary>
        public static void UPDATE()
        {
            // 1. Move now into then to store the last frame's input.
            // 2. Update now with the current device input.
            
            keeb_then = keeb_now;
            keeb_now = Keyboard.GetState();
            mous_then = mous_now;
            mous_now = Mouse.GetState();
            gam1_then = gam1_now;
            gam1_now = GamePad.GetState(PlayerIndex.One);
            gam2_then = gam2_now;
            gam2_now = GamePad.GetState(PlayerIndex.Two);
            gam3_then = gam3_now;
            gam3_now = GamePad.GetState(PlayerIndex.Three);
            gam4_then = gam4_now;
            gam4_now = GamePad.GetState(PlayerIndex.Four);
        }   //END FUNCTION UPDATE
    }   //END CLASS INPUT
}   //END NAMESPACE EIRIS
